package com.ct.boot.launch;

import com.ct.boot.launch.controller.ArticleController;
import jdk.nashorn.internal.ir.annotations.Ignore;
import lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.http.HttpMethod;
import org.springframework.test.context.junit.jupiter.SpringExtension;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.MvcResult;
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
import org.springframework.test.web.servlet.result.MockMvcResultMatchers;
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
import org.springframework.web.context.WebApplicationContext;

import javax.annotation.Resource;

/**
 * @Auther: 1
 * @Date: 2020/6/13 10:35
 * @Description:
 */
@Slf4j
//测试用例的自动注入
//为测试用例类加上spring运行时的servlet容器的环境
@SpringBootTest
@ExtendWith(SpringExtension.class)
@AutoConfigureMockMvc
@Ignore
public class ArticleResControllerTest2 {
//    //mock对象
//    //注入创建mock对象
//    @Resource
//    private  MockMvc mockMvc;
//    //构造方法创建对象
////    @BeforeAll
////    static void setUp(){
////        WebApplicationContext context;
////        mockMvc=MockMvcBuilders.standaloneSetup(new ArticleController()).build();
////
////    }
//
//    String article="{\"reader\":\n" +
//            "    [{\"name\":\"kobe\",\"age\":1},{\"name\":\"james\",\"age\":2}]}";
//    @Test
//    public void saveArticle()throws Exception{
//        MvcResult mvcResult=mockMvc.perform(
//                MockMvcRequestBuilders.request(HttpMethod.POST,"/articles/")
//                .contentType("application/json")
//                .content(article)
//        )
//                .andExpect(MockMvcResultMatchers.jsonPath("$.data.reader[1].age").value(2))
//         .andReturn();
//
//        System.out.println(11111111);
////        System.out.println(mvcResult.getResponse().getContentAsString());
//        log.info(mvcResult.getResponse().getContentAsString());
//    }

}
